﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using VOL.Core.Filters;
using VOL.Core.Utilities;
using VOL.Domain.IServices.MasterData;
using VOL.Entity.DomainModels;

namespace VOL.WebApi.Controllers.MasterData
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WorkshopSettingController : ControllerBase
    {
        private readonly IWorkshopSettingService _workshopSettingService;

        public WorkshopSettingController(IWorkshopSettingService workshopSettingService)
        {
            _workshopSettingService = workshopSettingService;
        }

        /// <summary>
        /// 添加车间设置
        /// </summary>
        /// <param name="workshopSetting">车间设置实体</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> AddWorkshopSetting([FromBody]WorkshopSetting workshopSetting)
        {
            return await _workshopSettingService.AddWorkshopSetting(workshopSetting);
        }

        /// <summary>
        /// 获取车间设置列表
        /// </summary>
        /// <param name="workshopCode">车间编码</param>
        /// <param name="workshopName">车间名称</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebResponseContent> GetWorkshopSettings(
            [FromQuery] string workshopCode,
            [FromQuery] string workshopName,
            [FromQuery] int pageIndex = 1,
            [FromQuery] int pageSize = 10)
        {
            return await _workshopSettingService.GetWorkshopSettings(workshopCode, workshopName, pageIndex, pageSize);
        }

        /// <summary>
        /// 更新车间设置
        /// </summary>
        /// <param name="workshopSetting">车间设置实体</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> UpdateWorkshopSetting([FromBody] WorkshopSetting workshopSetting)
        {
            return await _workshopSettingService.UpdateWorkshopSetting(workshopSetting);
        }

        /// <summary>
        /// 批量删除车间设置
        /// </summary>
        /// <param name="ids">要删除的ID数组</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebResponseContent> BatchDeleteWorkshopSettings([FromQuery] int[] ids)
        {
            return await _workshopSettingService.BatchDeleteWorkshopSettings(ids);
        }
    }
}
